package com.ssy.lingxi.purchase.api.enums.purchseplan;

import com.ssy.lingxi.common.language.LanguageHolder;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 采购计划内部状态 - enum
 * @author fhj
 * @date 2021/02/26
 * @version 2.0.0
 */
public enum PurchasePlanInnerStatusEnum {
    TO_BE_SUBMIT_EXAM(1, "待提交审核"),
    TO_BE_EXAM1(2, "待审核（一级）"),
    TO_BE_EXAM2(3, "待审核（二级）"),
    TO_BE_EXECUTE(4, "待执行"),
    EXECUTE_COMPLETE(5, "已完成"),
    NOT_PASSED1(8, "审核不通过（一级）"),
    NOT_PASSED2(9, "审核不通过（二级）");

    private Integer code;
    private String message;

    PurchasePlanInnerStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static String getMessage(Integer code) {
        PurchasePlanInnerStatusEnum workEnum = Arrays.stream(PurchasePlanInnerStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return null == workEnum ? "" : LanguageHolder.getName(PurchasePlanInnerStatusEnum.class, workEnum.getCode());
    }

    public static List<Map<String, Object>> getAll() {
        return Arrays.stream(PurchasePlanInnerStatusEnum.values()).map(a -> {
            String message = LanguageHolder.getName(PurchasePlanInnerStatusEnum.class, a.getCode());
            Map<String, Object> map = new HashMap<>();
            map.put("code", a.getCode());
            map.put("message", message);
            return map;
        }).collect(Collectors.toList());
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getClass(), this.code);
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
